{% load static %}
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>登录</title>
    <link rel="stylesheet" href="{% static 'hfui/plugins/layui/css/layui.css' %}" media="all"/>
    <link rel="stylesheet" href="{% static 'hfui/css/login.css' %}"/>

    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.js"></script>
    <script src="{% static 'js/jQuery.md5.js' %}"></script>
</head>

<body class="beg-login-bg">
<div class="beg-login-box">
    <header>
        <h1>海风技术部测试系统</h1>
    </header>
    <div class="beg-login-main">
        <form id="login-form" action="/manage/login" class="layui-form" method="post"><input
                name="__RequestVerificationToken" type="hidden"
                value="fkfh8D89BFqTdrE2iiSdG_L781RSRtdWOH411poVUWhxzA5MzI8es07g6KPYQh9Log-xf84pIR2RIAEkOokZL3Ee3UKmX0Jc8bW8jOdhqo81"/>
            {% csrf_token %}
            <div class="layui-form-item">
                <label class="beg-login-icon">
                    <i class="layui-icon">&#xe612;</i>
                </label>
                <input type="text" name="phone" lay-verify="userName" autocomplete="off" placeholder="这里输入登录名"
                       class="layui-input" value="15555555555">
            </div>
            <div class="layui-form-item">
                <label class="beg-login-icon">
                    <i class="layui-icon">&#xe642;</i>
                </label>
                <input type="password" name="password" lay-verify="password" autocomplete="off" placeholder="这里输入密码"
                       class="layui-input" value="111111">
            </div>
            <div class="layui-form-item">
                <div class="beg-pull-left beg-login-remember">
                    <label>记住帐号？</label>
                    <input type="checkbox" name="rememberMe" value="true" lay-skin="switch" checked title="记住帐号">
                </div>
                <div class="beg-pull-right">

							<span id="login-btn" class="layui-btn layui-btn-primary" lay-submit lay-filter="login">
                            <i class="layui-icon">&#xe650;</i> 登录
                        </span>
                </div>

                <div class="beg-clear"></div>
                <div class="login-tips" style="color: red"></div>
            </div>
        </form>
    </div>
    <footer>
        <p> © 海风教育</p>
    </footer>
</div>
<script type="text/javascript" src="{% static 'hfui/plugins/layui/layui.js' %}"></script>
<script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script>
    $.ajaxSetup({
        data: {csrfmiddlewaretoken: '{{ csrf_token }}'},
    });
    $(function () {

        //判断是否记录账号
        var isRememberUserName = $.cookie("rememberMe")
        console.log(isRememberUserName);
        if (isRememberUserName) {
            $("input[name=username]").val(isRememberUserName)
        }

        //清空form tips
        $("input").focus(function () {
            $(".login-tips").text('')
        })

        $("#login-btn").click(function () {
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.load();
            });
            var obj = {}

            $("#login-form input").each(function () {
                obj[$(this).attr('name')] = $.trim($(this).val());
            })

            //判断是否记录用户名
            if ($(".layui-unselect").hasClass('layui-form-onswitch')) {
                $.cookie("rememberMe", obj['username'])
            }
            obj['password'] = $.md5($.md5(obj['phone']) + $.md5(obj['password']))
            $.post('doLogin', obj, function (data) {
                if (data.code != 200) {
                    $('.login-tips').text(data.message).delay(3000).fadeOut();
                }
                else {
                    frm = '{{frm}}'
                    location.href = frm;
                }
                layui.use('layer', function () {
                    var layer = layui.layer.closeAll();
                });
            }, 'json')
        })
    })

</script>


</body>


</html>